function hideDiv(div_id) {
	$("#" + div_id).animate({
		opacity : "hide"
	}, 300);
}
function popupDiv(div_id) {
	var div_obj = $("#" + div_id);
	// 窗口宽度,高度
	var winWidth = $(window).width();
	var winHeight = $(window).height();
	// 弹出的div的宽度,高度
	var popHeight = div_obj.height();
	var popWidth = div_obj.width();
	div_obj.animate({
		opacity : "show",
		left : (winWidth - popWidth) / 2,
		top : (winHeight - popHeight) / 2,
		width : popWidth,
		height : popHeight
	}, 300);
}

$(function() {
	$(".pop_box").easydrag();
	$(".pop_box").setHandler(".pop_box .p_head");
});

function clickEditDossier(count, id, div_id) {

	if (!RolePowerManager()) {
		return;
	}

	var counts = [];
	for ( var i = 1; i <= 5; i++) {
		counts[i] = '#' + count + i;
	}

	$("#dosno_edit").val($(counts[1]).text());
	$("#empid_edit").val($(counts[2]).text());
	$("#dosname_edit").val($(counts[3]).text());
	$("#synopsis_edit").val($(counts[4]).text());
	$("#remark_edit").val($(counts[5]).text());

	$("#dossierid").val(id);
	popupDiv(div_id);
}

function addDossier() {

	if (!RolePowerManager()) {
		return;
	}

	var dosno = $("#dosno_add").val();
	var empid = $("#empid_add").val();
	var dosname = $("#dosname_add").val();
	var synopsis = $("#synopsis_add").val();
	var remark = $("#remark_add").val();

	if (dosno && empid && dosname) {
		DossierManagerService.addDossier(dosno, empid, dosname, synopsis,
				remark, function(data) {
					if (data) {
						alert("增加成功");
						location.reload("/GetDossierServlet");
					} else {
						alert("增加失败");
					}
				});
	} else {
		alert("有必填项未填！");
	}
}

function updateDossier() {

	var dosno = $("#dosno_edit").val();
	var empid = $("#empid_edit").val();
	var dosname = $("#dosname_edit").val();
	var synopsis = $("#synopsis_edit").val();
	var remark = $("#remark_edit").val();
	var id = $("#dossierid").val();

	if (dosno && empid && dosname) {
		DossierManagerService.updateDossier(id, dosno, empid, dosname,
				synopsis, remark, function(data) {
					if (data) {
						alert("修改成功");
						location.reload("/GetDossierServlet");
					} else {
						alert("修改失败");
					}
				});
	} else {
		alert("有必填项未填！");
	}
}

function deleteDossier(id) {

	if (!RolePowerManager()) {
		return;
	}

	DossierManagerService.deleteById(id, function(data) {
		if (data) {
			alert("修改成功");
			location.reload("/GetDossierServlet");
		} else {
			alert("修改失败");
		}
	});
}

function changePageSize() {
	var ps = $("#pageSize").val();
	location.href = "GetDossierServlet?pageSize=" + ps;
}

function search() {
	if ($("#searchtype").val() == "dosno" || $("#searchtype").val() == "empid") {

		if (isNaN($("#keycode").val())) {
			alert("请输入数字");
			return;
		}
	}
	$("#searchform").submit();
}
